<?php
/**
 * This file is form http://findcat.cn
 *
 * @link     https://findcat.cn
 * @email    1476982312@qq.com
 */
namespace App\Http\Controllers\Home;

use App\Models\Tag;
use App\Models\Article;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class TagController extends Controller
{
    /**
     * 获取所有标签.
     *
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index()
    {
        $tag = Tag::query()->get();

        $data = [
            'tags' => $tag,
        ];

        return view('home.tags', $data);
    }

    /**
     * 关于该标签的文章.
     *
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function show(Request $request)
    {
        $page = $request->page;

        $articles = Article::query()
            ->where('status', true)
            ->where('id','!=', 7)
            ->with(['tags'])
            ->paginate(10);

        $articles->page = $page;

        $tags = Tag::query()->limit(5)->get();

        $data = [
            'articles'  => $articles,
            'tags'      => $tags,
        ];

        return view('home.index', $data);
    }
}
